Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 11511 - Frieze Patterns / frieze.3.cpp
blobebcd93812b8d8078fa6e54838e150032e1516397
1 /*
2 Accepted
3 */
4 #include<iostream>
5 #include<cstdio>
6 #include<vector>
7 using namespace std;
9 int f[1005][1005];
11 int main(){
12 //assert(freopen("frieze.in", "r", stdin) != NULL);
13 int n, row, col;
14 while (cin >> n >> row >> col && n){
16 for (int i=1; i<=n; ++i) cin >> f[i][1];
18 for (int j=1; j<=n+1; ++j) f[1][j] = f[n][j] = 1;
20 for (int j=2; j<=n+1; ++j)
21 for (int i=2; i<n; ++i)
22 f[i][j] = (f[i+1][j-1]*f[i-1][j]+1)/f[i][j-1];
26 for (int i=1; i<=n; ++i){
27 for (int j=1; j<=n+1; ++j)
28 printf("%3d ", f[i][j]);
29 puts("");
32 if (col % (n+1) == 0) col = n+1;
33 else col %= (n+1);
35 cout << f[row][col] << endl;
37 return 0;